package gui.panel_new.evaluation.student;

import enums.*;
import gui.panel_new.evaluation.exeptions.ExerciseNotBuiltException;
import gui.panel_new.evaluation.exeptions.PunctuationZeroException;
import gui.panel_new.evaluation.professor.CreateSylogismViolationPanel;
import j_util.Utiles;
import misc.BundlesProvider;
import model.Polisilogismo;
import model.Premisa;
import model.Sylogism;
import model.eval.PolisylogismData;
import model.eval.SylogismData;
import model.eval.TestExcercise;

import javax.swing.*;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.ResourceBundle;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Extiende de ExercisePanel, permite resolver ejercicios en los que se construyen silogismos
 * a partir de las caracteristicas pedidas: figura, terminos, extensiones;
 *
 * @author Jose Martin Rozanec;
 */
public class PolisilogismoFromParameters extends ExercisePanel {
    private javax.swing.JPanel bottomPanel;
    private javax.swing.JTextField conclusionField;
    private javax.swing.JLabel conclusionLabel;
    private javax.swing.JPanel cuadroPanel;
    private javax.swing.JLabel figuraLabel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JTextField premisaMayorField;
    private javax.swing.JLabel premisaMayorLabel;
    private javax.swing.JTextField premisaMenorField;
    private javax.swing.JLabel premisaMenorLabel;
    private javax.swing.JLabel terminoMayorLabel;
    private javax.swing.JLabel terminoMedioLabel;
    private javax.swing.JLabel terminoMenorLabel;
    private javax.swing.JTextArea textArea;
    private JCheckBox primeraFiguraCheckBox;
    private JCheckBox segundaFiguraCheckBox;
    private JCheckBox terceraFiguraCheckBox;
    private JCheckBox cuartaFiguraCheckBox;
    private JTextField terminoMayorField;
    private JTextField terminoMedioField;
    private JTextField terminoMenorField;

    private JRadioButton a1;
    private JRadioButton a2;
    private JRadioButton a3;
    private JRadioButton e1;
    private JRadioButton e2;
    private JRadioButton e3;
    private JRadioButton i1;
    private JRadioButton i2;
    private JRadioButton i3;
    private JRadioButton o1;
    private JRadioButton o2;
    private JRadioButton o3;

    private JLabel addsPoints;
    private JLabel substractPoints;
    private JTextField addsPointsField;
    private JTextField substractPointsField;

    private JButton previousButton;
    private JButton nextButton;
    private JLabel currentOverTotalLabel;
    private JPanel topButtonsPanel;

    private Color bcgColor;

    private int premisaLabelsStringLength;
    private ResourceBundle textBundle;

    private Sylogism sylogism;
    private Polisilogismo polisilogismo;
    private java.util.List<Sylogism> silogismosList;
    private FigureEnum figure;
    private PolisylogismData polisylogismData;

    /**
     * Constructor;
     */
    public PolisilogismoFromParameters() {
        testPanelEnum = TestPanelEnum.CREAR_POLISILOGISMO;
        this.sylogism = new Sylogism();
        silogismosList = new ArrayList<Sylogism>();
        premisaLabelsStringLength = 10;
        textBundle = BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE);
        initComponents();
    }

    /**
     * Inicializa componentes;
     */
    private void initComponents() {
        bcgColor = Color.WHITE;
        mainPanel = new javax.swing.JPanel();
        cuadroPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        premisaMayorField = new javax.swing.JTextField();
        premisaMayorLabel = new javax.swing.JLabel();
        premisaMenorLabel = new javax.swing.JLabel();
        premisaMenorField = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        conclusionLabel = new javax.swing.JLabel();
        conclusionField = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        figuraLabel = new javax.swing.JLabel();
        terminoMayorLabel = new javax.swing.JLabel();
        terminoMedioLabel = new javax.swing.JLabel();
        terminoMenorLabel = new javax.swing.JLabel();
        bottomPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        textArea = new javax.swing.JTextArea();

        addsPoints = new JLabel(textBundle.getString(TextBundleEnum.SUMA.toString()));
        substractPoints = new JLabel(textBundle.getString(TextBundleEnum.RESTA.toString()));
        addsPointsField = new JTextField(3);
        addsPointsField.setEditable(false);
        substractPointsField = new JTextField(3);
        substractPointsField.setEditable(false);

        previousButton = new JButton(Utiles.createImageIcon(URLEnum.getReference(URLEnum.ANTERIOR)));
        previousButton.setMinimumSize(new Dimension(80, 25));
        previousButton.setPreferredSize(new Dimension(80, 25));
        previousButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Premisa premisa = sylogism.getPremisa(PremisaTypeEnum.FIRST);
                resetSylogismTextFields();
                sylogism = new Sylogism();
                sylogism.setPremisa(premisa, PremisaTypeEnum.CONCLUSION);

                setSylogismData(polisylogismData.previous());
                setSylogism(sylogism);
                if (polisylogismData.getCurrentNumber() != 1) {
                    conclusionField.setEditable(false);
                } else {
                    conclusionField.setEditable(true);
                }
                premisaMayorField.setEditable(true);
                managePreviousNextButtons();
            }
        });
        nextButton = new JButton(Utiles.createImageIcon(URLEnum.getReference(URLEnum.SIGUIENTE)));
        nextButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Premisa premisa = sylogism.getPremisa(PremisaTypeEnum.CONCLUSION);
                resetSylogismTextFields();
                sylogism = new Sylogism();
                sylogism.setPremisa(premisa, PremisaTypeEnum.FIRST);

                setSylogismData(polisylogismData.next());
                setSylogism(sylogism);
                if (polisylogismData.getCurrentNumber() != 1) {
                    premisaMayorField.setEditable(false);
                } else {
                    premisaMayorField.setEditable(true);
                }
                conclusionField.setEditable(true);
                managePreviousNextButtons();
            }
        });
        nextButton.setMinimumSize(new Dimension(80, 25));
        nextButton.setPreferredSize(new Dimension(80, 25));
        currentOverTotalLabel = new JLabel("::/::");

        mainPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
                new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true),
                textBundle.getString(TextBundleEnum.SILOGISMO.toString())));

        cuadroPanel.setBackground(new java.awt.Color(255, 255, 255));
        cuadroPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(
                new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true),
                textBundle.getString(TextBundleEnum.SILOGISMO.toString())));

        premisaMayorField.addCaretListener(new CaretListener() {
            public void caretUpdate(CaretEvent e) {
                if (Premisa.isComplete(premisaMayorField.getText())) {
                    sylogism.setPremisa(new Premisa(premisaMayorField.getText()), PremisaTypeEnum.FIRST);
                    premisaMayorField.setForeground(new Color(0, 0, 0));
                    saveExercise();
                } else {
                    sylogism.setPremisa(null, PremisaTypeEnum.FIRST);
                    premisaMayorField.setForeground(new Color(255, 0, 0));
                }
            }
        });

        premisaMenorField.addCaretListener(new CaretListener() {
            public void caretUpdate(CaretEvent e) {
                if (Premisa.isComplete(premisaMenorField.getText())) {
                    sylogism.setPremisa(new Premisa(premisaMenorField.getText()), PremisaTypeEnum.SECOND);
                    premisaMenorField.setForeground(new Color(0, 0, 0));
                    saveExercise();
                } else {
                    sylogism.setPremisa(null, PremisaTypeEnum.SECOND);
                    premisaMenorField.setForeground(new Color(255, 0, 0));
                }
            }
        });

        conclusionField.addCaretListener(new CaretListener() {
            public void caretUpdate(CaretEvent e) {
                if (Premisa.isComplete(conclusionField.getText())) {
                    sylogism.setPremisa(new Premisa(conclusionField.getText()), PremisaTypeEnum.CONCLUSION);
                    conclusionField.setForeground(new Color(0, 0, 0));
                    saveExercise();
                } else {
                    sylogism.setPremisa(null, PremisaTypeEnum.CONCLUSION);
                    conclusionField.setForeground(new Color(255, 0, 0));
                }
            }
        });

        premisaMayorLabel.setText(Utiles.getFormattedString(
                textBundle.getString(TextBundleEnum.PREMISA_MAYOR.toString()), ""));
        premisaMayorLabel.setHorizontalTextPosition(SwingConstants.LEFT);
        premisaMayorLabel.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.PREMISA_LARGO)));

        premisaMenorLabel.setText(Utiles.getFormattedString(
                textBundle.getString(TextBundleEnum.PREMISA_MENOR.toString()), ""));
        premisaMenorLabel.setHorizontalTextPosition(SwingConstants.LEFT);
        premisaMenorLabel.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.PREMISA_LARGO)));

        jSeparator1.setForeground(new java.awt.Color(0, 0, 0));

        conclusionLabel.setText(Utiles.getFormattedString(
                textBundle.getString(TextBundleEnum.CONCLUSION.toString()), ""));
        conclusionLabel.setHorizontalTextPosition(SwingConstants.LEFT);
        conclusionLabel.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.CONCLUSION_LARGO)));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(
                new java.awt.Color(204, 204, 204), 1, true), textBundle.getString(TextBundleEnum.FIGURA.toString())));

        primeraFiguraCheckBox = new JCheckBox(textBundle.getString(TextBundleEnum.PRIMERA_FIGURA.toString()));
        primeraFiguraCheckBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                figure = FigureEnum.FIRST;
            }
        });
        segundaFiguraCheckBox = new JCheckBox(textBundle.getString(TextBundleEnum.SEGUNDA_FIGURA.toString()));
        segundaFiguraCheckBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                figure = FigureEnum.SECOND;
            }
        });
        terceraFiguraCheckBox = new JCheckBox(textBundle.getString(TextBundleEnum.TERCERA_FIGURA.toString()));
        terceraFiguraCheckBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                figure = FigureEnum.THIRD;
            }
        });
        cuartaFiguraCheckBox = new JCheckBox(textBundle.getString(TextBundleEnum.CUARTA_FIGURA.toString()));
        cuartaFiguraCheckBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                figure = FigureEnum.FOURTH;
            }
        });

        ButtonGroup group = new ButtonGroup();
        group.add(primeraFiguraCheckBox);
        group.add(segundaFiguraCheckBox);
        group.add(terceraFiguraCheckBox);
        group.add(cuartaFiguraCheckBox);

        figuraLabel.setIcon(Utiles.createImageIcon(URLEnum.getReference(URLEnum.FIGURA_NONE)));

        terminoMayorField = new JTextField(10);
        terminoMedioField = new JTextField(10);
        terminoMenorField = new JTextField(10);

        terminoMayorLabel.setText(textBundle.getString(TextBundleEnum.TERMINO_MAYOR.toString()) + ":");
        terminoMedioLabel.setText(textBundle.getString(TextBundleEnum.TERMINO_MEDIO.toString()) + ":");
        terminoMenorLabel.setText(textBundle.getString(TextBundleEnum.TERMINO_MENOR.toString()) + ":");

        jPanel3 = createTerminosPanel();

//        bottomPanel.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true), "Sugerencias y Analisis"), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)));
        bottomPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(
                new java.awt.Color(204, 204, 204), 1, true),
                textBundle.getString(TextBundleEnum.EXTENSION_PARTES.toString())));

        a1 = new JRadioButton("A");
        a2 = new JRadioButton("A");
        a3 = new JRadioButton("A");
        e1 = new JRadioButton("E");
        e2 = new JRadioButton("E");
        e3 = new JRadioButton("E");
        i1 = new JRadioButton("I");
        i2 = new JRadioButton("I");
        i3 = new JRadioButton("I");
        o1 = new JRadioButton("O");
        o2 = new JRadioButton("O");
        o3 = new JRadioButton("O");

        jScrollPane1.setViewportView(textArea);

        bottomPanel.getAccessibleContext().setAccessibleName(textBundle.getString(TextBundleEnum.ANALISIS.toString()));

        sizeTextFields();
        sizeTextAreas();
        enableTerminos(false);
        layoutComponents();
    }

    /**
     * Realiza el layout de los componentes visuales;
     */
    private void layoutComponents() {
        setBackground(bcgColor);
        setLayout(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        int x = 0;
        int y = 0;
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);
        jPanel1.setLayout(new GridBagLayout());

        /*      PREMISAS     */
        jPanel1.add(premisaMayorLabel, gridBagConstraints);

        gridBagConstraints.gridx = (x += 7);
        jPanel1.add(new JLabel(), gridBagConstraints);

        gridBagConstraints.gridx = (x -= 7);
        gridBagConstraints.gridy = ++y;
        gridBagConstraints.gridwidth = 5;
        jPanel1.add(premisaMayorField, gridBagConstraints);

        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridx = (x += 6);

        jPanel1.add(new JLabel(), gridBagConstraints);

        gridBagConstraints.gridx = (x += 1);
        jPanel1.add(new JLabel(), gridBagConstraints);

        gridBagConstraints.gridx = (x -= 7);
        gridBagConstraints.gridy = ++y;
        jPanel1.add(premisaMenorLabel, gridBagConstraints);

        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.gridy = ++y;
        jPanel1.add(premisaMenorField, gridBagConstraints);

        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridx = (x += 6);
        jPanel1.add(new JLabel(), gridBagConstraints);

        gridBagConstraints.gridx = (x += 1);
        jPanel1.add(new JLabel(), gridBagConstraints);

        gridBagConstraints.gridwidth = 7;
        gridBagConstraints.gridx = (x -= 7);
        gridBagConstraints.gridy = ++y;
        jSeparator1.setPreferredSize(new Dimension(550, 2));
        jPanel1.add(jSeparator1, gridBagConstraints);

        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridy = ++y;
        jPanel1.add(conclusionLabel, gridBagConstraints);

        gridBagConstraints.gridy = ++y;
        gridBagConstraints.gridwidth = 5;
        jPanel1.add(conclusionField, gridBagConstraints);

        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridx = (x += 6);
        jPanel1.add(new JLabel(), gridBagConstraints);

        gridBagConstraints.gridx = (x += 1);
        jPanel1.add(new JLabel(), gridBagConstraints);

        jPanel1.setMinimumSize(new Dimension(655, 250));
        jPanel1.setPreferredSize(new Dimension(655, 250));
        x = 0;
        y = 0;
        /*      END OF PREMISAS     */

        /*      BUTTONS     */
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = y;
        gridBagConstraints.gridwidth = 3;

        topButtonsPanel = new JPanel();
        topButtonsPanel.setBorder(BorderFactory.createEtchedBorder());
        topButtonsPanel.setBackground(bcgColor);
//        topButtonsPanel.add(createScoringPanel());
        topButtonsPanel.add(addsPoints);
        topButtonsPanel.add(addsPointsField);
        topButtonsPanel.add(substractPoints);
        topButtonsPanel.add(substractPointsField);
        topButtonsPanel.add(new JLabel(Utiles.createImageIcon(URLEnum.getReference(URLEnum.SEPARATOR_110))));
        topButtonsPanel.add(new JLabel(Utiles.createImageIcon(URLEnum.getReference(URLEnum.SEPARATOR_110))));
        topButtonsPanel.add(new JLabel(Utiles.createImageIcon(URLEnum.getReference(URLEnum.SPACE_OP))));
        topButtonsPanel.add(new JLabel(Utiles.createImageIcon(URLEnum.getReference(URLEnum.SPACE_OP))));
        topButtonsPanel.add(previousButton);
        topButtonsPanel.add(currentOverTotalLabel);
        topButtonsPanel.add(nextButton);


        topButtonsPanel.setMinimumSize(new Dimension(655, 35));
        topButtonsPanel.setPreferredSize(new Dimension(655, 35));

        add(topButtonsPanel, gridBagConstraints);
        gridBagConstraints.gridy = ++y;
        add(jPanel1, gridBagConstraints);

        JPanel buttonsPanel = new JPanel(new GridLayout(1, 7));
        buttonsPanel.setBackground(bcgColor);

        gridBagConstraints.gridy = ++y;
        add(buttonsPanel, gridBagConstraints);
        /*      END OF BUTTONS     */

        jPanel2.setMinimumSize(new Dimension(215, 175));
        jPanel2.setPreferredSize(new Dimension(215, 175));
        jPanel2.setLayout(new GridLayout(4, 1));
        jPanel2.add(primeraFiguraCheckBox);
        jPanel2.add(segundaFiguraCheckBox);
        jPanel2.add(terceraFiguraCheckBox);
        jPanel2.add(cuartaFiguraCheckBox);

        JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        panel.setBackground(bcgColor);
        gridBagConstraints.insets = new Insets(0, 25, 0, 25);
        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        panel.add(jPanel2, gridBagConstraints);
        gridBagConstraints.gridx = 1;
        panel.add(jPanel3, gridBagConstraints);

        gridBagConstraints.gridwidth = 3;//1
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = ++y;
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);
        add(panel, gridBagConstraints);

        jPanel3.setMinimumSize(new Dimension(250, 175));
        jPanel3.setPreferredSize(new Dimension(250, 175));//430

        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = ++y;

        bottomPanel.setBackground(bcgColor);
        bottomPanel.setMinimumSize(new Dimension(655, 1400));
        bottomPanel.setPreferredSize(new Dimension(655, 140));
        bottomPanel.setLayout(new GridBagLayout());
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.insets = new Insets(10, 20, 10, 20);
        bottomPanel.add(createExtensionRow(
                new JLabel(textBundle.getString(TextBundleEnum.PREMISA_MAYOR.toString())), a1, e1, i1, o1), constraints);
        constraints.gridx = 1;
        bottomPanel.add(createExtensionRow(
                new JLabel(textBundle.getString(TextBundleEnum.PREMISA_MENOR.toString())), a2, e2, i2, o2), constraints);
        constraints.gridy = 1;
        constraints.gridx = 0;
        constraints.gridwidth = 2;
        constraints.insets = new Insets(10, 60, 10, 50);
        bottomPanel.add(createExtensionRow(
                new JLabel(textBundle.getString(TextBundleEnum.CONCLUSION.toString())), a3, e3, i3, o3), constraints);
        add(bottomPanel, gridBagConstraints);
    }

    private JPanel createScoringPanel() {
        JPanel scoringPanel = new JPanel();
        scoringPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
                textBundle.getString(TextBundleEnum.PUNTAJE.toString())));
        scoringPanel.setLayout(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);
        scoringPanel.add(addsPoints, gridBagConstraints);
        gridBagConstraints.gridx = 1;
        scoringPanel.add(addsPointsField, gridBagConstraints);
        gridBagConstraints.gridx = 2;
        scoringPanel.add(substractPoints, gridBagConstraints);
        gridBagConstraints.gridx = 3;
        scoringPanel.add(substractPointsField, gridBagConstraints);
        scoringPanel.setBackground(bcgColor);
        return scoringPanel;
    }

    private JPanel createTerminosPanel() {
        JPanel panel = new JPanel();
        panel.setBackground(new java.awt.Color(255, 255, 255));
        panel.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(
                new java.awt.Color(204, 204, 204), 1, true), textBundle.getString(TextBundleEnum.TERMINOS.toString())));
        panel.setLayout(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(6, 5, 5, 5);
        panel.add(terminoMayorLabel, gridBagConstraints);
        gridBagConstraints.gridx = 1;
        panel.add(terminoMayorField, gridBagConstraints);
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridx = 0;
        panel.add(terminoMedioLabel, gridBagConstraints);
        gridBagConstraints.gridx = 1;
        panel.add(terminoMedioField, gridBagConstraints);
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridx = 0;
        panel.add(terminoMenorLabel, gridBagConstraints);
        gridBagConstraints.gridx = 1;
        panel.add(terminoMenorField, gridBagConstraints);
        return panel;
    }

    /**
     * Determina el tamano de los textFields;
     */
    private void sizeTextFields() {
        premisaMayorField.setColumns(45);
        premisaMayorField.setMinimumSize(new Dimension(550, 20));
        premisaMayorField.setEditable(true);
        premisaMenorField.setColumns(45);
        premisaMenorField.setMinimumSize(new Dimension(550, 20));
        premisaMenorField.setEditable(true);
        conclusionField.setColumns(45);
        conclusionField.setMinimumSize(new Dimension(550, 20));
        conclusionField.setEditable(true);
    }

    /**
     * Determina el tamano de los textAreas;
     */
    private void sizeTextAreas() {
        textArea.setColumns(58);
        textArea.setEditable(false);
        textArea.setRows(7);
        textArea.setPreferredSize(new Dimension(550, 110));
    }

    public TestExcercise getExercise() throws ExerciseNotBuiltException, PunctuationZeroException {
//        polisilogismo = Polisilogismo.getPolisilogismoFromSylogisms(silogismosList);
        testExercise.setStudentsSolution(silogismosList);
        System.out.println("Estoy retirando el ejercicio! El silogismo que me llevo es: " + sylogism);
        return testExercise;
    }

    public void setExercise(TestExcercise testExercise) {
        this.testExercise = testExercise;
        polisylogismData = (PolisylogismData) testExercise.getExcerciseData();
        setSylogismData(polisylogismData.getCurrent());
        silogismosList = (java.util.List<Sylogism>) testExercise.getStudentsSolution();
        addsPointsField.setText("" + testExercise.getCorrectScore());//todo ver!
        substractPointsField.setText("" + testExercise.getIncorrectScore());//todo ver!
        managePreviousNextButtons();
    }

    private void enableTerminos(boolean enable) {
        terminoMayorField.setEnabled(enable);
        terminoMedioField.setEnabled(enable);
        terminoMenorField.setEnabled(enable);
    }

    private void setSylogismData(SylogismData data) {
        if (data.getPremisaMayorExtension() != null) {
            setExtension(data.getPremisaMayorExtension(), a1, e1, i1, o1);
        }
        if (data.getPremisaMenorExtension() != null) {
            setExtension(data.getPremisaMenorExtension(), a2, e2, i2, o2);
        }
        if (data.getConclusionExtension() != null) {
            setExtension(data.getConclusionExtension(), a3, e3, i3, o3);
        }
        if (data.getTerminoMayor() != null) {
            terminoMayorField.setText(data.getTerminoMayor());
        }
        if (data.getTerminoMedio() != null) {
            terminoMedioField.setText(data.getTerminoMedio());
        }
        if (data.getTerminoMenor() != null) {
            terminoMenorField.setText(data.getTerminoMenor());
        }
        if (data.getFigura() != null) {
            setFigura(data.getFigura());
        }
    }

    private void setExtension(ExtensionEnum extension, JRadioButton a, JRadioButton e,
                              JRadioButton i, JRadioButton o) {
        a.setSelected(false);
        e.setSelected(false);
        i.setSelected(false);
        o.setSelected(false);

        a.setEnabled(false);
        e.setEnabled(false);
        i.setEnabled(false);
        o.setEnabled(false);

        switch (extension) {
            case A:
                a.setSelected(true);
                break;
            case E:
                e.setSelected(true);
                break;
            case I:
                i.setSelected(true);
                break;
            case O:
                o.setSelected(true);
                break;
        }
    }

    private void setFigura(FigureEnum figure) {
        primeraFiguraCheckBox.setSelected(false);
        segundaFiguraCheckBox.setSelected(false);
        terceraFiguraCheckBox.setSelected(false);
        cuartaFiguraCheckBox.setSelected(false);

        primeraFiguraCheckBox.setEnabled(false);
        segundaFiguraCheckBox.setEnabled(false);
        terceraFiguraCheckBox.setEnabled(false);
        cuartaFiguraCheckBox.setEnabled(false);

        switch (figure) {
            case FIRST:
                primeraFiguraCheckBox.setSelected(true);
                break;
            case SECOND:
                segundaFiguraCheckBox.setSelected(true);
                break;
            case THIRD:
                terceraFiguraCheckBox.setSelected(true);
                break;
            case FOURTH:
                cuartaFiguraCheckBox.setSelected(true);
                break;
        }
    }

    private JPanel createExtensionRow(JLabel label, JRadioButton a, JRadioButton e,
                                      JRadioButton i, JRadioButton o) {
        ButtonGroup group = new ButtonGroup();
        group.add(a);
        group.add(e);
        group.add(i);
        group.add(o);
        JPanel panel = new JPanel(new GridBagLayout());
        panel.setBackground(bcgColor);
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);
        gridBagConstraints.gridwidth = 4;
        panel.add(label, gridBagConstraints);
        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridx = 4;
        panel.add(a, gridBagConstraints);
        gridBagConstraints.gridx = 5;
        panel.add(e, gridBagConstraints);
        gridBagConstraints.gridx = 6;
        panel.add(i, gridBagConstraints);
        gridBagConstraints.gridx = 7;
        panel.add(o, gridBagConstraints);
        return panel;
    }

    public void setSylogism(Sylogism sylogism) {
        this.sylogism = sylogism;
        if (sylogism.getPremisa(PremisaTypeEnum.FIRST) != null) {
            premisaMayorField.setText(sylogism.getPremisa(PremisaTypeEnum.FIRST).toString());
        }
        if (sylogism.getPremisa(PremisaTypeEnum.SECOND) != null) {
            premisaMenorField.setText(sylogism.getPremisa(PremisaTypeEnum.SECOND).toString());
        }
        if (sylogism.getPremisa(PremisaTypeEnum.CONCLUSION) != null) {
            conclusionField.setText(sylogism.getPremisa(PremisaTypeEnum.CONCLUSION).toString());
        }
    }

    private void resetSylogismTextFields() {
        premisaMayorField.setText("");
        premisaMenorField.setText("");
        conclusionField.setText("");
    }

    private void managePreviousNextButtons() {
        if (polisylogismData.getCurrentNumber() == polisylogismData.getTotalSylogisms()) {
            nextButton.setEnabled(false);
        } else {
            nextButton.setEnabled(true);
        }
        if (polisylogismData.getCurrentNumber() == 1) {
            previousButton.setEnabled(false);
        } else {
            previousButton.setEnabled(true);
        }
        if (polisylogismData == null) {
            currentOverTotalLabel.setText("::/::");
        } else {
            currentOverTotalLabel.setText(
                    "" + polisylogismData.getCurrentNumber() + "/" + polisylogismData.getTotalSylogisms());
        }

    }

    private void saveExercise() {
        if(silogismosList.size()<polisylogismData.getCurrentNumber()){
            silogismosList.add(sylogism);
        }else{
            silogismosList.set(polisylogismData.getCurrentNumber() - 1, sylogism);
        }
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("SilogismoPanel");
        frame.setContentPane(new CreateSylogismViolationPanel(new JButton(), new JButton(), new JFileChooser()));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
